package com.example.basic.web.controller.remains;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.basic.core.result.Result;
import com.example.basic.core.result.ResultGenerator;
import com.example.basic.custom.Log;
import com.example.basic.web.model.pharmZone.PharmZone;
import com.example.basic.web.model.remains.RemainsInfo;
import com.example.basic.web.response.RemainFlowVo;
import com.example.basic.web.service.pharmZone.PharmZoneService;
import com.example.basic.web.service.remains.RemainsInfoService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.checkerframework.checker.units.qual.A;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;


@Api(value  = "遗体信息", tags = {"遗体信息"})
@RestController
@RequestMapping("/api/v1/byg/remains")
public class RemainsInfoController {

    @Resource
    private RemainsInfoService remainsInfoService;

    @Log(title = "遗体基础信息", description = "新增或修改")
    @ApiOperation(value = "新增或修改", notes = "新增或修改")
    @PostMapping("/addOrUpdate")
    public Result<RemainsInfo> addOrUpdate(@ApiParam(name = "remainsInfo", value = "模型", required = true) @RequestBody RemainsInfo remainsInfo) {
        return ResultGenerator.genSuccessResult(remainsInfoService.addOrUpdate(remainsInfo));
    }


    @Log(title = "遗体基础信息", description = "删除")
    @ApiOperation(value = "删除", notes = "删除")
    @PostMapping("/remove")
    public Result<Boolean> remove(@ApiParam(name = "remainsCode", value = "遗体编码") @RequestParam String remainsCode ) {
        return ResultGenerator.genSuccessResult(remainsInfoService.remove(remainsCode));
    }

    @Log(title = "遗体基础信息", description = "列表")
    @ApiOperation(value = "列表", notes = "列表")
    @PostMapping("/queryList")
    public Result<IPage<RemainsInfo>> queryList(
            @ApiParam(name = "searchParam", value = "模糊搜索(拼音码,五笔码,名称)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "sex", value = "性别 0-全部") @RequestParam(defaultValue = "0") String sex,
            @ApiParam(name = "cremation", value = "火化方式 0-全部") @RequestParam(defaultValue = "0") String cremation,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<RemainsInfo> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(remainsInfoService.queryList(queryPage,searchParam, sex,cremation));
    }

    @Log(title = "遗体基础信息", description = "待入库列表")
    @ApiOperation(value = "待入库列表", notes = "待入库列表")
    @PostMapping("/waitInList")
    public Result<IPage<RemainsInfo>> waitInList(
            @ApiParam(name = "searchParam", value = "模糊搜索(拼音码,五笔码,名称)") @RequestParam(required = false) String searchParam,
            @ApiParam(name = "sex", value = "性别 0-全部") @RequestParam(defaultValue = "0") String sex,
            @ApiParam(name = "beginTime", value = "开始日期 yyyy-mm-dd") @RequestParam(required = false) String beginTime,
            @ApiParam(name = "endTime", value = "结束日期 yyyy-mm-dd") @RequestParam(required = false) String endTime,
            @ApiParam(name = "page", value = "页数，list分页的第几页") @RequestParam(defaultValue = "0") Integer page,
            @ApiParam(name = "size", value = "条数，list分页的每页条数") @RequestParam(defaultValue = "0") Integer size) {
        Page<RemainsInfo> queryPage = new Page<>(page,size);
        return ResultGenerator.genSuccessResult(remainsInfoService.waitInList(queryPage,searchParam, sex,beginTime,endTime));
    }

    @ApiOperation(value = "yt详情", notes = "yt详情")
    @GetMapping("/detail")
    public Result<RemainFlowVo> detail(@ApiParam(name = "remainsCode", value = "yt编码") @RequestParam String remainsCode,
                                       @ApiParam(name = "roleCode", value = "角色Code") @RequestParam String roleCode,
                                       @ApiParam(name = "userId", value = "用户id") @RequestParam String userId)  {
        return ResultGenerator.genSuccessResult(remainsInfoService.detailPda(remainsCode,userId,roleCode));
    }

    @ApiOperation(value = "yt详情", notes = "yt详情")
    @GetMapping("/selectFlow")
    public Result<RemainFlowVo> selectFlow(@ApiParam(name = "remainsCode", value = "yt编码") @RequestParam String remainsCode,
                                       @ApiParam(name = "roleCode", value = "角色Code") @RequestParam String roleCode,
                                       @ApiParam(name = "userId", value = "用户id") @RequestParam String userId)  {
        return ResultGenerator.genSuccessResult(remainsInfoService.selectFlow(remainsCode,userId,roleCode));
    }
}
